/*  HostMon/msntop - A simple program to monitor hosts on android
	Copyright (C) 2009 Robert Chou

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation version 2 of the License. 

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.android.msntop.services;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;


/**
 */
public class WebUtils {
	public static final String LOG_TAG = WebUtils.class.getSimpleName();

	public static final int CONN_TIMEOUT = 5000;
	public static final int READ_TIMEOUT = 15000;

	/**
	 */
	 public static int doHeadUrl( String strUrl )
	 {
		 int output = -1;

		 try
		 {
			 HttpClient httpClient = new DefaultHttpClient();
			 httpClient.getParams().setParameter("http.socket.timeout", CONN_TIMEOUT);

			 HttpHead method = new HttpHead( strUrl );
			 method.setHeader( "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)" );            
			 method.getParams().setParameter("http.socket.timeout", READ_TIMEOUT);

			 HttpResponse response = httpClient.execute(method);
			 output = response.getStatusLine().getStatusCode();
		 }
		 catch( Exception e )
		 {
			 Log.d( LOG_TAG, "failed to head url: " + strUrl, e );
		 }            

		 return output;
	 }       


}
